<%@page import="org.compiere.dsr.DSR_Cell"%>
<%@page import="org.compiere.model.MBPMFormCode"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%@ taglib prefix="s" uri="/struts-tags" %>    

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ page import="main.org.form.action.FormBP, main.org.form.action.Forms, main.org.model.*, org.compiere.model.*, org.compiere.util.Env" %>
<%@ page import="org.compiere.dsr.DSR_DataCollection" %>

<%
	FormBP fBP = (FormBP) session.getAttribute("formBP");
	Forms formsBP = (Forms) session.getAttribute("forms"); 
	MBPMFormCode formCode = new MBPMFormCode(Env.getCtx(), fBP.getFormCodeID(), null);
	DSR_DataCollection collection = fBP.getCollection();
	int rowSpan = collection.size();
	int rowC = 1;
	int colC = 0;
%>

<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>Ввод данных по формам БО для ДЗО</title>
		<link rel="shortcut icon" href="images/logo.png" type="image/jpg" /> 	
		<link type="text/css" href="css/Main.css" rel="stylesheet">
		<%@ include file="/js/JScript.jsp" %>
	</head>
<body>
	<div>
		<div id="back" class="letter">
			<a class="aBack" title="Вернуться назад" href="<s:url action='forms'>
				<s:param name="AD_PInstance_ID"><%= formsBP.getAD_PInstance_ID() %></s:param>
			</s:url>" >
				<img src="images/back.png" />
			</a>
		</div>
		<s:url id="excelDownload" namespace="/" action="DownloadBP" >
			<s:param name="page"><s:property value="page" /></s:param>
			<s:param name="projectID"><s:property value="projectID" /></s:param>
			<s:param name="orgID"><s:property value="orgID" /></s:param>
			<s:param name="formID"><s:property value="formID" /></s:param>
			<s:param name="formCodeID"><s:property value="formCodeID" /></s:param>
		</s:url>
		<div id="printExcel" class="letterRight letter">
			<s:a href="%{excelDownload}" title="Выгрузка в Excel"><img src="images/excel.png" style="margin-left: 10px;" /></s:a>
			<img src="images/separator.png" style="margin-left: 5px;" />
			<a href='javascript:window.print(); void 0;' title="Печать"><img src="images/print.png" style="margin-left: 5px;" /></a>
		</div>
		<table width="100%" cellspacing="2" align="center">
			<tr>
				<td scope="col">
				   	<font color="#321818" style="font-family: sans-serif; font-style:italic" size="+2">Ввод данных по бюджетным формам</font>
				   	<br/>&nbsp;
				</td>
			</tr>
		</table>
		
		<%@ include file="/jsp/budgetcall/PropertyForm.jsp" %>
		<table width="60%" cellspacing="2" style="margin-left: 150px;">
				 <tr>
				 	<td width="20%" style="border:double; border-color:#F18800; text-align: left; padding-left: 10px;">
				 		<font color="#321818" style="font-family: sans-serif; font-style:normal;" size="+1">Форма</font>
				 	</td>
				 	<td style="border:dotted; border-color:#999999; width:40%; text-align: left; padding-left: 10px;">
				 		<b><%= formCode.getName() %></b>
				 	</td>
				</tr>
		</table>
		<s:form id="myFormBP">
			<table class="cursorHover more" border="1" style="margin-top:20px;" bordercolor="#663300" align="center" cellspacing="2" id="tableBP">
				<tr class="trLightBlue">

				<% 
				DSR_Cell cell = null;
				for(int h = 0; h < collection.getHeader().size(); h++){
					cell = collection.getHeader().getCell(h);
					String formula = cell.getFormula(); 

				%>
							<s:set var="formula"><%= cell.getFormula() %></s:set>

					<th scope="col" id="column<%= h %>" title="<%= formula %>" >
    <s:if test="%{#formula!='null'}">
<input id="checkbox<%= h %>" type="checkbox" name="checkbox<%= h %>" onchange = 'hideunhide("checkbox<%= h %>", "<%= formula %>");'"/>
    </s:if>
						<%= cell.getValue() %>
					</th>
				<%
				}
				%>
				</tr>
				<%
				for(int i=0; i < collection.size(); i++){
					%>
					<tr>
					<%
					colC = 0;
					for(int j=0; j < collection.getRow(i).size(); j++){
						cell = collection.getRow(i).getCell(j);
						%>
							<s:set var="cellValue"><%= cell.getValue() %></s:set>
							<s:set var="col"><%= colC %></s:set> 
							<s:set var="row"><%= rowC %></s:set> 
							<s:set var="formula"><%= cell.getFormula() %></s:set>
							<%
							if(cell.isRow){
								%>
								<td class="tdRow" width="650px">
								<%=  FormBP.getNBSP(cell.LevelIndex) %> &nbsp; <%= cell.getValue() %> 
								</td>
								<%
							}else{
							%>
								<td bgcolor="#DAE1EA">
    <s:if test="#formula == 'null'">
        <s:set var="readonly" value="'false'" />
        <s:set var="class" value="''" />
    </s:if>
    <s:else>
        <s:set var="readonly" value="'true'" />
        <s:set var="class" value="'notchange'" />
    </s:else> 

<s:textfield value="%{#cellValue}" 
                          title="%{#formula}" 
 cssClass="%{#class}"

name="cell_Row%{#row}_Col%{#col}" id="cell_Row%{#row}_Col%{#col}" size="15" 
theme="simple" readonly="%{#readonly}" 
onkeypress="return isAmountUnit(event)"
onchange="changeValue('cell_Row%{#row}_Col%{#col}', this, 'cellCopy_Row%{#row}_Col%{#col}',%{collection.size()},%{collection.getRow(1).size()-1});" /> 
									<s:hidden name="cellCopy_Row%{#row}_Col%{#col}" id="cellCopy_Row%{#row}_Col%{#col}" value="%{#cellValue}" />
								</td>
						<%	}
						colC++;
					}
					%>
					</tr>
					<%
					rowC++;
				}
				rowC--;
				colC--;
			%>
			<tr>
				<th style="border:double; border-color:#F18800; text-align: center; padding-left: 10px;" bgcolor="#E6F0FA" colspan="<%= collection.getRow(0).size() %>" height="40px;">
					<input type="button" class="button btn-large-green" value="Внести изменения" onclick="sendFormBP('doUpdateBP');" />
					<input type="hidden" name="rowspan" value=<%= rowSpan %> />	
					<input type="hidden" name="formID" value=<%= fBP.getFormID() %> />
					<input type="hidden" name="projectID" value=<%= fBP.getProjectID() %> />
					<input type="hidden" name="orgID" value=<%= fBP.getAD_Org_ID() %> />
					<input type="hidden" name="ProjectSubID" value=<%= fBP.getProjectSubID() %> />
					<input type="hidden" name="userID" value=<%= fBP.getUserID() %> />
				</th>
			</tr>
			</table>
		</s:form>
	</div>
	
	<script type="text/javascript">
			countRow = <%= rowC %>
			countCol = <%= colC %>
	</script>		
</body>
</html>